home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / matrix.lha / Matrix / evaluate.C < prev    next >
C/C++ Source or Header  |  1992-03-26  |  2KB  |  81 lines

  1. #include <math.h>
  2. #include <bool.h>
  3. #include <GetOpt.h>
  4. #include <double.Matrix.h>
  5. #define  matrix doubleMatrix
  6. #define  array  doubleArray
  7.  
  8. int
  9. main (int argc, char **argv)
  10.   {
  11.     int        verbose  = FALSE;        // verbose reporting off
  12.     int        xgraph   = FALSE;        //  graph style output
  13.     GetOpt    getopt (argc, argv, "vx");
  14.  
  15.   int option;
  16.   while ((option = getopt()) != EOF)
  17.     switch (option)
  18.       {
  19.         case 'v':                // verbose reporting on
  20.       verbose    = TRUE;
  21.           break;
  22.         case 'x':                // xgraph style output
  23.       xgraph    = TRUE;
  24.           break;
  25.         case '?':
  26.           cerr << "Unrecognized option!\n";
  27.       };
  28.  
  29.     int        layers; cin >> layers;        // number of layers
  30.     matrix    b[layers];            // threshold  biases
  31.     matrix    W[layers];            // connection weights
  32.     matrix    x[layers+1];            // inputs
  33.  
  34.     int        outputs; cin >> outputs;    // number of outputs
  35.     int        inputs = outputs;        // number of  inputs
  36.     if (verbose)
  37.       cerr << "N(" << inputs;
  38.     for (int layer = 0; layer < layers; layer++)
  39.       {
  40.     int inputs = outputs;
  41.     cin >> outputs;
  42.     if (verbose)
  43.       cerr << ", " << outputs;
  44.     x[layer].resize(inputs);
  45.     W[layer].resize(outputs, inputs);
  46.         b[layer].resize(outputs);
  47.     for (int output = 0; output < outputs; output++)
  48.           cin >> b[layer][0][output] >> W[layer].s(output);
  49.       };
  50.     x[layers].resize(outputs);
  51.  
  52.     int        examples; cin >> examples;    // number of examples
  53.     if (verbose)
  54.       cerr << ")\t" << examples << " examples\n";
  55.     matrix    X(examples,  inputs);        //  inputs
  56.     matrix    Y(examples, outputs);        // outputs
  57.     for (int example = 0; example < examples; example++)
  58.       cin >> X.s(example) >> Y.s(example);
  59.  
  60.     for (int output = 0; output < outputs; output++)
  61.       {
  62.     if (xgraph)
  63.       cout << "\"" << output << "\"\n";
  64.     for (int example = 0; example < examples; example++)
  65.       {
  66.         x[0]     = X.s(example);
  67.  
  68.       //for (int layer = 0; layer < layers; layer++)
  69.       //  x[layer+1] = tanh(b[layer] + x[layer]%W[layer]);
  70.         for (int layer = 0; layer < layers-1; layer++)
  71.           x[layer+1] = tanh(b[layer] + x[layer]%W[layer]);
  72.         x[layers] = b[layers-1] + x[layers-1]%W[layers-1];
  73.  
  74.         cout << form("%10.3e\t", Y[example][output])
  75.          << form("%10.3e\n", x[layers][0][output]);
  76.       };
  77.     cout << "\n";
  78.       };
  79.     cout.flush();
  80.   }
  81.